directory<-Sys.getenv("US_Ineq_Repl")
CEPR<-file.path(directory, "Data/CEPR")
ORG<-file.path(CEPR, "CPS_ORG/CEPR")
BASIC<-file.path(CEPR, "CPS_Basic/CEPR")
NBER_O<-file.path(CEPR, "CPS_ORG/NBER")
NBER_B<-file.path(CEPR, "CPS_Basic/NBER")

getOption('timeout')
options(timeout=1200)

Y<-c(sprintf("%02d", 94:99),sprintf("%02d", 0:20))
m<-c('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec')
r<-0
for (yy in 1994:2020) {
  dir.create(file.path(NBER_B, yy), showWarnings = FALSE)
  for (mm in m) {
    f<-paste0(file.path(NBER_B, yy),'/',mm,Y[yy-1994+1],'pub.zip')
    if(!file.exists(f)){
      u<-paste0('https://www2.census.gov/programs-surveys/cps/datasets/',
                yy,'/basic/',mm,Y[yy-1994+1],'pub.zip')
      r<-download.file(u, f, mode = "wb")
    }
    if(r!=0){
      cat(paste0('problem in year ',yy,' month ',mm,'\n'))
    }
  }
}
